package com.qf.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.qf.exceptions.ResultCode;

/**
 * @Author ztf
 * @Date 16:54 2021/12/29
 *当前类是接口的统一的返回结果类
 **/
@JsonInclude(JsonInclude.Include.NON_EMPTY)//只解析不为空的数据,注意"" 也算空,也就是只返回有效数据
public class R {
    /**
     * 状态码
     */
    private int code;
    /**
     * 提示信息
     */
    private String msg;
    /**
     * 携带的数据
     */
    private Object data;

    public static R setOK(){
        return setOK(null);
    }
    public static R setOK(Object data){
        return setError(ResultCode.SUCCESS, "成功", data);

    }

    public static R setError(int code, String msg) {
        return setError(code, msg, null);
    }

    public static R setError(int code, String msg, Object data) {
        R result = new R();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
